package com.dubbo.service.bootstrap;

import com.dubbo.bootstrap.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.File;
import java.util.Scanner;

import static com.dubbo.StaticConstants.LEAGUE_CONTENT_PATH;
import static com.dubbo.StaticConstants.LEAGUE_JETTY_PORT;
import static com.dubbo.StaticConstants.LEAGUE_NETTY_PORT;

/**
 * @author Zhuyanfeng on 2018/3/20
 */

public class Start {

    private static Logger logger = LoggerFactory.getLogger(Start.class);

    @SuppressWarnings("all")
    public static void main(String[] args) throws Exception {
       startDubbo();
    }

    private static String computerContentPathByClassPath() {
        String classpath = Start.class.getClassLoader().getResource(".").getPath();
        return new File(classpath).getParentFile().getParent();
    }

    public static void startDubbo(){
        logger.info("starting dubbo...........");
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        ctx.refresh();
        ctx.start();
        Scanner scan = new Scanner(System.in);
        System.out.println("service started");
        Boolean wait = true;
        while (wait) {
            String result = scan.nextLine();
            while (!result.equals("stop")) {
                System.out.println("service continue");
                result = scan.nextLine();
            }
            System.out.println("are you sure stop services?");
            result = scan.nextLine();
            if (!result.equals("y")) {
                System.out.println("service continue");
                continue;
            }
            wait = false;
        }
        System.out.println("service end");
        ctx.close();
        scan.close();
        logger.info("starting dubbo successfully...........");

    }
}
